﻿using System.ComponentModel.DataAnnotations;
using BLL.Services.Users;
using Web.Infrastructure.Models;

namespace Web.Models.Account
{
    public class RegisterModel : BaseModel
    {
        public RegisterModel()
        {
        }
        [Required]
        [RegularExpression("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")]
        public string Email { get; set; }

        [Compare("ConfirmPassword")]
        [Required]
        [StringLength(256)]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        public string ConfirmPassword { get; set; }

        public static User operator +(User user, RegisterModel model)
        {
            ToEntity(model, user);
            user.SetPassword(model.Password);
            return user;
        }
    }
}